#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <openssl/evp.h>

//Sprawdzenie:
//$ echo "AAAA" | md5sum   = ae5b468c7707a1f3d36c49b1fe2ef850 

main( int argc, char *argv[] )
{
EVP_MD_CTX 	mdctx;
const EVP_MD 	*md;
char		mess1[] = "AAA";
char		mess2[] = "A\n";
unsigned char	md_value[EVP_MAX_MD_SIZE];
int		md_len, i;

OpenSSL_add_all_digests();

if( !argv[1] )
{
printf("Użycie: piec nazwa_hasza_np_md5\n");
exit(1);
}

md = EVP_get_digestbyname( argv[1] );

if( !md )
{
printf("Eeee, nie znam takiego hasza %s\n", argv[1]);
exit(1);
}

EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx);
printf("Hasz w hex: ");

for(i = 0; i < md_len; i++)
 {
 printf("%02x", md_value[i]);
 }

printf("\n");
}
